package pe.gob.mpfn.model;

import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

@Entity
@Table(name = "desarrollo_proteccion")
@Configurable
@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "desarrollo_proteccion")
@RooDbManaged(automaticallyDelete = true)
public class DesarrolloProteccion {

	@ManyToOne
    @JoinColumn(name = "int_personal_id", referencedColumnName = "int_personal_id", nullable = false)
    private Personal intPersonalId;

	@ManyToOne
    @JoinColumn(name = "int_proteccion_id", referencedColumnName = "int_proteccion_id", nullable = false)
    private Proteccion intProteccionId;

	@Column(name = "str_descripcion", columnDefinition = "VARCHAR", length = 200)
    @NotNull
    private String strDescripcion;

	@Column(name = "dat_fecha_registro", columnDefinition = "DATETIME")
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date datFechaRegistro;

	@Column(name = "chr_estado", columnDefinition = "CHAR")
    @NotNull
    private Character chrEstado;

	@Column(name = "desarrollo_proteccioncol", columnDefinition = "VARCHAR", length = 45)
    @NotNull
    private String desarrolloProteccioncol;

	public Personal getIntPersonalId() {
        return intPersonalId;
    }

	public void setIntPersonalId(Personal intPersonalId) {
        this.intPersonalId = intPersonalId;
    }

	public Proteccion getIntProteccionId() {
        return intProteccionId;
    }

	public void setIntProteccionId(Proteccion intProteccionId) {
        this.intProteccionId = intProteccionId;
    }

	public String getStrDescripcion() {
        return strDescripcion;
    }

	public void setStrDescripcion(String strDescripcion) {
        this.strDescripcion = strDescripcion;
    }

	public Date getDatFechaRegistro() {
        return datFechaRegistro;
    }

	public void setDatFechaRegistro(Date datFechaRegistro) {
        this.datFechaRegistro = datFechaRegistro;
    }

	public Character getChrEstado() {
        return chrEstado;
    }

	public void setChrEstado(Character chrEstado) {
        this.chrEstado = chrEstado;
    }

	public String getDesarrolloProteccioncol() {
        return desarrolloProteccioncol;
    }

	public void setDesarrolloProteccioncol(String desarrolloProteccioncol) {
        this.desarrolloProteccioncol = desarrolloProteccioncol;
    }

	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "int_desarrollo_proteccion_id", columnDefinition = "INT")
    private Integer intDesarrolloProteccionId;

	public Integer getIntDesarrolloProteccionId() {
        return this.intDesarrolloProteccionId;
    }

	public void setIntDesarrolloProteccionId(Integer id) {
        this.intDesarrolloProteccionId = id;
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	@PersistenceContext
    transient EntityManager entityManager;

	public static final EntityManager entityManager() {
        EntityManager em = new DesarrolloProteccion().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	public static long countDesarrolloProteccions() {
        return entityManager().createQuery("SELECT COUNT(o) FROM DesarrolloProteccion o", Long.class).getSingleResult();
    }

	public static List<DesarrolloProteccion> findAllDesarrolloProteccions() {
        return entityManager().createQuery("SELECT o FROM DesarrolloProteccion o", DesarrolloProteccion.class).getResultList();
    }

	public static DesarrolloProteccion findDesarrolloProteccion(Integer intDesarrolloProteccionId) {
        if (intDesarrolloProteccionId == null) return null;
        return entityManager().find(DesarrolloProteccion.class, intDesarrolloProteccionId);
    }

	public static List<DesarrolloProteccion> findDesarrolloProteccionEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM DesarrolloProteccion o", DesarrolloProteccion.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

	@Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	@Transactional
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            DesarrolloProteccion attached = DesarrolloProteccion.findDesarrolloProteccion(this.intDesarrolloProteccionId);
            this.entityManager.remove(attached);
        }
    }

	@Transactional
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	@Transactional
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	@Transactional
    public DesarrolloProteccion merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        DesarrolloProteccion merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }
}
